#ifndef ROBOT_H
#define ROBOT_H

/*
 * robot.h
 * This is the code for the robot function, which draws the robot
 
 it asumes that several things exist in the main opengl program:
 - a variable spinner and spin function
 - GLUquadricObj *cylinder; is globally declared--for drawing cylinders
 - the lines:   
   cylinder=gluNewQuadric();
   gluQuadricNormals(cylinder, GLU_SMOOTH);
   are present in init
 - Face culling is DISABLED

  by Tom Rutherford
 */

#include <stdlib.h>

//#include <GL/gl.h>
//#include <GL/glut.h>
//#include <GL/glu.h>

//mac includes
//#include <OpenGL/gl.h>   // OpenGL itself.
//#include <OpenGL/glu.h>  // GLU support library.
//#include <GLUT/glut.h> // GLUT support library.

//STUFF THAT NEEDS TO BE ADDED
float spinner=0;
GLUquadricObj *cylinder;
//END STUFF

//By Tom Rutherford: Draw the robot
void robot(int head){
  int i=0;
  int antennaSlices=8;
  glColor3f(0.6,0.6,0.6);
  //body is a 5 by 5 by 10 rectangle
  //GLfloat bodyColor[] = { 0.1, 0.1, 0.11};
  //glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, bodyColor);

  //body 
  //base 5x5
  glBegin(GL_QUADS);
  glColor3f(0.6f, 0.6f, 0.6f);
  glVertex3f(2.5, 1, 2.5);
  glVertex3f(-2.5, 1, 2.5);
  glVertex3f(-2.5, 1, -2.5);
  glVertex3f(2.5, 1, -2.5);
  glEnd();

  //top
  glBegin(GL_QUADS);
  glVertex3f(2.5, 11, 2.5);
  glVertex3f(2.5, 11, -2.5);
  glVertex3f(-2.5, 11, -2.5);
  glVertex3f(-2.5, 11, 2.5);
  glEnd();

  //sides 10 tall
  for(i=0; i<4; i++){
    glRotated(90*i, 0,1,0);
    
    glBegin(GL_QUADS);
    glVertex3f(2.5, 1, 2.5);
    glVertex3f(2.5, 1, -2.5);
    glVertex3f(2.5, 11, -2.5);
    glVertex3f(2.5, 11, 2.5);
    glEnd();
  }
  glRotated(90, 0,1,0); //back to original rotation

  //front and back decorations, green and blue
  //front 4x9
  glColor3f(0, 0.6, 0);
  glBegin(GL_QUADS);
  glVertex3f(2, 2, 2.51);
  glVertex3f(-2, 2, 2.51);
  glVertex3f(-2, 10, 2.51);
  glVertex3f(2, 10, 2.51);
  glEnd();

  //back
  glColor3f(0,0,0.6);
  glBegin(GL_TRIANGLES);
  glVertex3f(-2, 2,-2.51);
  glVertex3f(2, 2, -2.51);
  glVertex3f(0,6,-2.51);
  glEnd();

  glBegin(GL_TRIANGLES);
  glVertex3f(-2, 6,-2.51);
  glVertex3f(2, 6, -2.51);
  glVertex3f(0,10,-2.51);
  glEnd();

  glColor3f(0.6, 0.6, 0.6);


  //head 1 above body, 4 x 3 x 3
  //rotate here to turn head
  glRotated(85*head, 0,1,0);

  //base
  glBegin(GL_QUADS);
  glVertex3f(2, 12, 1.5);
  glVertex3f(-2, 12, 1.5);
  glVertex3f(-2, 12, -1.5);
  glVertex3f(2, 12, -1.5);
  glEnd();

  //top
  glBegin(GL_QUADS);
  glVertex3f(2, 14, 1.5);
  glVertex3f(2, 14, -1.5);
  glVertex3f(-2, 14, -1.5);
  glVertex3f(-2, 14, 1.5);
  glEnd();

    //
  for(i=0; i<2; i++){
    glRotated(180*i, 0,1,0);
    
      glBegin(GL_QUADS);
      glVertex3f(2, 12, 1.5);
      glVertex3f(2, 12, -1.5);
      glVertex3f(2, 14, -1.5);
      glVertex3f(2, 14, 1.5);
      glEnd();
  }
  
  glRotated(180, 0,1,0); //back to original rotation
  //glRotated(90, 0,1,0);

    //front/back
  for(i=0; i<2; i++){
    glRotated(180*i, 0,1,0);
    
      glBegin(GL_QUADS);
      glVertex3f(-2, 12, 1.5);
      glVertex3f(2, 12, 1.5);
      glVertex3f(2, 14, 1.5);
      glVertex3f(-2, 14, 1.5);
      glEnd();
  }


  //neck and antenna
  glRotated(-90, 1,0,0);
  glTranslated(0,0,11);
  gluCylinder(cylinder, 1,1,1, 32, 1); //neck
  
  glRotated(spinner, 0,0,1);
  glTranslated(0,0,3);
  glColor3f(.8,.6,0);
  gluCylinder(cylinder, 0.5,0.5,2, antennaSlices, 1); //antenna
  glTranslated(0,0,2);
  gluDisk(cylinder, 0,0.5, antennaSlices, 1); //top of antenna

   //side thingies
  glRotated(90, 1,0,0);
  glTranslated(0,-0.25,-1);
  gluCylinder(cylinder, 0.1,0.1,4, antennaSlices, 1); //sidetenna

  glTranslated(0,-.25,2);
  glRotated(180, 1,0,0);
  gluCylinder(cylinder, 0.1,0.1,4, antennaSlices, 1); //sidetenna
  glRotated(-180, 1,0,0);
  glTranslated(0,.25,-2);

  glTranslated(0,-.5,0);
  gluCylinder(cylinder, 0.1,0.1,4, antennaSlices, 1); //sidetenna
  glTranslated(0,.5,0);

  glTranslated(0,0.25,1);
  glRotated(-90, 1,0,0);
  //end side thingies

  glRotated(-spinner, 0,0,1);
  glTranslated(0,0,-16);
  glColor3f(0.6,0.6,0.6);

  glRotated(90, 1,0,0); //back at origin again

  //eyes
  glRotated(180, 0,1,0);
  glTranslated(0,13,0);
  glTranslated(0,0,1.505);

  //left
  glTranslated(1,0,0);
  gluCylinder(cylinder, 0.5,0.5,0.25, 32, 1);
  glColor3f(1,0,0);
  gluDisk(cylinder, 0,0.5, 32, 1);
  glColor3f(.6,.6,.6);
  glTranslated(-1,0,0);

  //right
  glTranslated(-1,0,0);
  gluCylinder(cylinder, 0.5,0.5,0.25, 32, 1);
  glColor3f(1,0,0);
  gluDisk(cylinder, 0,0.5, 32, 1);
  glColor3f(.6,.6,.6);
  glTranslated(1,0,0);

  glTranslated(0,-13,-1.505); 
  glRotated(180, 0,1,0); //back to origin again
  
  glRotated(-85*head, 0,1,0);//undo head rotate

  

}

#endif
